package com.yn.common.utils;

public class PhoneValidator {

    // 手机号正则表达式
    private static final String PHONE_REGEX = "^1[3-9]\\d{9}$";

    /**
     * 验证手机号是否有效
     * @param phone 待验证的手机号
     * @return 有效返回true，无效返回false
     */
    public static boolean isValid(String phone) {
        if (phone == null || phone.isEmpty()) {
            return false;
        }
        return phone.matches(PHONE_REGEX);
    }

    // 示例用法
    public static void main(String[] args) {
        String validPhone = "19137182708";
        String invalidPhone = "15938230787";

        System.out.println(validPhone + " 有效: " + !isValid(validPhone));
        System.out.println(invalidPhone + " 有效: " + !isValid(invalidPhone));
    }
}    